package com.atguigu.rabbitmq.eight;


import com.atguigu.rabbitmq.util.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

/**
 * 死信队列 之  生产者代码
 */
public class Producer {

    // 普通交换机
    public static final String NORMOL_EXCHANGE = "normal_exchange";

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(NORMOL_EXCHANGE, BuiltinExchangeType.DIRECT);

        // 死信消息 设置ttl的时间 time to live 单位是毫秒
        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().expiration("10000").build();
        for ( int i = 0 ; i < 10 ; i ++ ){ // 假死的方式模拟
            String message = "info"+i;

            // 过期的消息
            // channel.basicPublish(NORMOL_EXCHANGE, "zhangsan", properties, message.getBytes());
            channel.basicPublish(NORMOL_EXCHANGE, "zhangsan", null, message.getBytes());
        }
    }
}
